package de.jmda.gen.java.impl;

import java.util.LinkedList;
import java.util.List;

import de.jmda.gen.Generator;
import de.jmda.gen.impl.AbstractCompoundGenerator;
import de.jmda.gen.java.InstanceFieldDeclarationGenerator;
import de.jmda.gen.java.InstanceFieldDeclarationsGenerator;

/**
 * Maintains a list of {@link InstanceFieldDeclarationGenerator}s in {@link
 * #generators}.
 *
 * @author rwegner
 */
public class DefaultInstanceFieldDeclarationsGenerator
		extends AbstractCompoundGenerator
		implements InstanceFieldDeclarationsGenerator
{
	private List<InstanceFieldDeclarationGenerator> generators;

	public DefaultInstanceFieldDeclarationsGenerator()
  {
	  super();
	  setComponentSeparator(DOUBLE_LINE_SEPARATOR);
  }

	/**
	 * @return list of <code>Generator</code>s with the return values of the
	 *         following methods in the following order:
	 *         <ul>
	 *           <li>{@link #getGenerators()}</li>
	 *         </ul>
	 *
	 * @see de.jmda.gen.CompoundGenerator#getGeneratorComponents()
	 */
	@Override
  public List<Generator> getGeneratorComponents()
  {
		// copy specific generators to non-specific generators and make Java happy
		List<Generator> result = new LinkedList<Generator>();

		result.addAll(getGenerators());
		
		return result;
  }

	/**
	 * @see de.jmda.gen.java.InstanceFieldDeclarationsGenerator#getGenerators()
	 */
	@Override
  public List<InstanceFieldDeclarationGenerator> getGenerators()
  {
		if (generators == null)
		{
			generators = new LinkedList<InstanceFieldDeclarationGenerator>();
		}
		
		return generators;
  }

	@Override
	public boolean add(InstanceFieldDeclarationGenerator generator)
	{
		return getGenerators().add(generator);
	}
}